/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.common.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: erp-cloud-api - MapUtils</p>
 * <p>Powered by yzc On 2024-01-23 11:44:29</p>
 * <p>描述：<p>
 *
 * @author yzc [youzhicheng0415@163.com]
 * @version 1.0
 * @since 17
 */
public class MapUtils {
    public static Map convert(Object object)  {
        Map map = new HashMap<>();
        //获得类的类型
        Class clazz = object.getClass();
        //获得声明的属性
        Field[] fields =clazz.getDeclaredFields();
        //遍历
        for (Field f : fields){
            //获得属性名
            String name =f.getName();
            //更改访问权限
            f.setAccessible(true);
            //获得属性值
            Object value = null;
            try {
                value = f.get(object);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            map.put(name,value);
        }
        return map;
    }
}
